package com.autonavi.abs.common.util;

import java.util.Random;

/**
 * @author wwy
 * @version V1.0
 * <p>Description: 随机数</p>
 * @date 2020-07-23 14:17
 */
public class RandomUtils {

    private static final int max = 999999;
    private static final int min = 100000;
    private static Random rand = new Random();

    private static Random rd = new Random();
    private static char[] constant = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    /**
     * 6位随机码
     *
     * @return
     */
    public static String get6RandomCode() {
        int tmp = Math.abs(rand.nextInt());
        return String.valueOf((tmp % (max - min + 1) + min));
    }

    /**
     * 指定长度随机码
     *
     * @param length
     * @return
     */
    public static String getRandomCode(int length) {
        StringBuilder newRandom = new StringBuilder(62);
        for (int i = 0; i < length; i++) {
            newRandom.append(constant[rd.nextInt(10)]);
        }
        return newRandom.toString();
    }


}
